package com.mega.ycy.mixin;

import com.mega.ycy.Yiciyuan_EVENT;
import net.minecraft.client.renderer.culling.ICamera;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

@Mixin(RenderManager.class)
public class EntityRenderMixin {
    /**
     * @author renderEntity
     */
    @Inject(method = "func_188391_a", at = @At("HEAD"), cancellable = true)
    public void render(Entity entityIn, double x, double y, double z, float yaw, float partialTicks, boolean p_188391_10_, CallbackInfo ci) {
        Yiciyuan_EVENT.RENDERABLE_ENTITIES.add(entityIn);
        if (Yiciyuan_EVENT.isDeath(entityIn) && !(entityIn instanceof EntityPlayer)) {
            Yiciyuan_EVENT.killEntity(entityIn);
            entityIn.addedToChunk = false;
            entityIn.isDead = true;
            ci.cancel();
        }
    }

    /**
     * @author renderEntity
     */
    @Inject(method = "func_188388_a", at = @At("HEAD"), cancellable = true)
    public void renderEntityStatic(Entity entityIn, float partialTicks, boolean p_188388_3_, CallbackInfo ci) {
        Yiciyuan_EVENT.RENDERABLE_ENTITIES.add(entityIn);
        if (Yiciyuan_EVENT.isDeath(entityIn) && !(entityIn instanceof EntityPlayer)) {
            Yiciyuan_EVENT.killEntity(entityIn);
            ci.cancel();
        }
    }

    /**
     * @author renderDebugBoundingBox
     */
    @Inject(method = "func_85094_b", at = @At("HEAD"), cancellable = true)
    private void renderDebugBoundingBox(Entity entityIn, double x, double y, double z, float entityYaw, float partialTicks, CallbackInfo ci){
        if (Yiciyuan_EVENT.isDeath(entityIn))
            ci.cancel();
    }

    /**
     * @author shouldRender
     */
    @Inject(method = "func_178635_a", at = @At("HEAD"), cancellable = true)
    private void shouldRender(Entity entityIn, ICamera camera, double camX, double camY, double camZ, CallbackInfoReturnable<Boolean> cir){
        if (Yiciyuan_EVENT.isDeath(entityIn))
            cir.setReturnValue(false);
    }
 }
